// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Core;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using Elastic.Transport;
using System;
using System.Runtime.Serialization;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Sql;

[JsonConverter(typeof(SqlFormatConverter))]
public enum SqlFormat
{
	[EnumMember(Value = "yaml")]
	Yaml,
	[EnumMember(Value = "txt")]
	Txt,
	[EnumMember(Value = "tsv")]
	Tsv,
	[EnumMember(Value = "smile")]
	Smile,
	[EnumMember(Value = "json")]
	Json,
	[EnumMember(Value = "csv")]
	Csv,
	[EnumMember(Value = "cbor")]
	Cbor
}

internal sealed class SqlFormatConverter : JsonConverter<SqlFormat>
{
	public override SqlFormat Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
	{
		var enumString = reader.GetString();
		switch (enumString)
		{
			case "yaml":
				return SqlFormat.Yaml;
			case "txt":
				return SqlFormat.Txt;
			case "tsv":
				return SqlFormat.Tsv;
			case "smile":
				return SqlFormat.Smile;
			case "json":
				return SqlFormat.Json;
			case "csv":
				return SqlFormat.Csv;
			case "cbor":
				return SqlFormat.Cbor;
		}

		ThrowHelper.ThrowJsonException();
		return default;
	}

	public override void Write(Utf8JsonWriter writer, SqlFormat value, JsonSerializerOptions options)
	{
		switch (value)
		{
			case SqlFormat.Yaml:
				writer.WriteStringValue("yaml");
				return;
			case SqlFormat.Txt:
				writer.WriteStringValue("txt");
				return;
			case SqlFormat.Tsv:
				writer.WriteStringValue("tsv");
				return;
			case SqlFormat.Smile:
				writer.WriteStringValue("smile");
				return;
			case SqlFormat.Json:
				writer.WriteStringValue("json");
				return;
			case SqlFormat.Csv:
				writer.WriteStringValue("csv");
				return;
			case SqlFormat.Cbor:
				writer.WriteStringValue("cbor");
				return;
		}

		writer.WriteNullValue();
	}
}